package com.bbtShop.core.utils;
import com.bbtShop.core.model.PageDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author manke
 * @Date 2020/9/1 10:05
 * @Version 0.0.1
 */
@Component
public class PageUtil {
    @Autowired
    public HttpServletRequest request;


    public static PageDto getPage(String pageNum, String pageSize) {
        PageDto pageDto = new PageDto();
        pageDto.setPageNum(pageNum == null || "".equals(pageNum) ? 1 : Integer.parseInt(pageNum));
        pageDto.setPageSize(pageSize == null || "".equals(pageSize) ? 10 : Integer.parseInt(pageSize));
        return pageDto;
    }
    public  PageDto getPage() {
        String pageNum = request.getHeader("pageNum");
        String pageSize = request.getHeader("pageSize");
        PageDto pageDto = new PageDto();
        pageDto.setPageNum(pageNum == null || "".equals(pageNum) ? 1 : Integer.parseInt(pageNum));
        pageDto.setPageSize(pageSize == null || "".equals(pageSize) ? 10 : Integer.parseInt(pageSize));
        return pageDto;
    }

}
